package com.producteev.version0.test;

import com.producteev4j.exceptions.ProducteevException;
import com.producteev4j.model.response.DashBoard;
import com.producteev4j.model.response.UserLogin;
import com.producteev4j.services.ProducteevService;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by IntelliJ IDEA.
 * User: jcarrey
 * Date: 3/07/11
 * Time: 21:16
 * To change this template use File | Settings | File Templates.
 */
public class ITTestDashboardProducteevServices {

    private static ProducteevService service;


    @Before
    public void setUp() {
        if (service == null) {
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext-test.xml");
            service = (ProducteevService) applicationContext.getBean("service");
        }
    }

    private static final String EMAIL = "juankarrey@gmail.com";
    private static final String PASSWORD = "pr0duc733v4j";

    private static final long ID_DASHBOARD = 146402;
    private static final long USER_ID = 107379L;

    private static String userToken;
    private static DashBoard dashboard;

    @Test
    public void testUserLogin() throws ProducteevException {
        UserLogin userLogin = service.userLogin(EMAIL, PASSWORD);
        userToken = userLogin.getToken();
    }


    @Test
    public void testCreateDashboard() throws ProducteevException {
        dashboard = service.createDashboard(userToken, "New DashBoard !");
    }


    @Test
    public void testgetDashboard() throws ProducteevException {
        service.getDashboard(userToken, ID_DASHBOARD);
    }


    @Test
    public void testgetDashboards() throws ProducteevException {
        service.getDashboards(userToken, null, 1);
    }


    @Test
    public void testgetDashboardAccess() throws ProducteevException {
        service.getDashboardAccess(userToken, ID_DASHBOARD);
    }


    @Test
    public void testleaveOrDelegateDashboard() throws ProducteevException {
        service.leaveOrDelegateDashboard(userToken, dashboard.getIdDashboard(), USER_ID, USER_ID);
    }


    @Test
    public void testsetTitle() throws ProducteevException {
        service.setTitle(userToken, dashboard.getIdDashboard(), "Other title for dashboard");
    }


    /* TODO - doesn't work "Wrong Value" returned.
    @Test  public void testsetSmartLabels() throws ProducteevException {
         service.setSmartLabels(userToken, dashboard.getIdDashboard(), 0);
     } */


    @Test
    public void testgetDashboardTasks() throws ProducteevException {
        service.getDashboardTasks(userToken, ID_DASHBOARD, null, 1);
    }


    @Test
    public void testconfirmInvitation() throws ProducteevException {
        service.confirmInvitation(userToken, dashboard.getIdDashboard());
    }


    @Test
    public void testrefuseInvitation() throws ProducteevException {
        service.refuseInvitation(userToken, dashboard.getIdDashboard());
    }


    @Test
    public void testinviteUserById() throws ProducteevException {
        service.inviteUserById(userToken, dashboard.getIdDashboard(), USER_ID);
    }


    @Test
    public void testinviteUserByEmail() throws ProducteevException {
        service.inviteUserByEmail(userToken, dashboard.getIdDashboard(), "juankarrey@gmail.com");
    }


    @Test
    public void testgetDashboardsToUpgrade() throws ProducteevException {
        service.getDashboardsToUpgrade(userToken);
    }


    @Test
    public void testneedsUpgrade() throws ProducteevException {
        service.needsUpgrade(userToken, ID_DASHBOARD);
    }

    @Test
    public void testdeleteDashboard() throws ProducteevException {
        service.deleteDashboard(userToken, dashboard.getIdDashboard());
    }


}
